package com.rui.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rui.admin.mapper.DeliveryMapper;
import com.rui.common.pojo.Delivery;
import com.rui.admin.service.DeliveryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class DeliveryServiceImpl implements DeliveryService {

    @Resource
    DeliveryMapper deliveryMapper;

    @Override
    public int riderRegister(Delivery delivery) {
        return deliveryMapper.riderRegister(delivery);
    }

    /*根据oid获取taker*/
    @Override
    public Delivery findTakerByOid(Integer oid) {
        return deliveryMapper.findTakerByOid(oid);
    }

    /*根据phone查询rider*/
    @Override
    public Delivery findDeliveryByPhone(String phone) {
        return deliveryMapper.findDeliveryByPhone(phone);
    }

    /*分页查询所有骑手*/
    @Override
    public HashMap<String,Object> findAllRidersByPage(String currentPage, Integer pageSize) {
        //查询总骑手数
        PageHelper.startPage(Integer.parseInt(currentPage), pageSize);
        List<Delivery> list = deliveryMapper.findAllRidersByPage();
        PageInfo<Delivery> pageInfo = new PageInfo<>(list);
        List<Delivery> deliveries =pageInfo.getList();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("deliveries",deliveries);
        hashMap.put("count",pageInfo.getTotal());
        return hashMap;
    }

    /*根据did获取delivery*/
    @Override
    public Delivery findDeliveryByDid(Integer did) {
        return deliveryMapper.findDeliveryByDid(did);
    }

}
